﻿Public Class FINRECODE
    Private RCODE As Integer = Nothing
    Private CCODE As Integer = Nothing
    Private NAMER As String = Nothing
    Private STATUS = Nothing
    Private SelectFinrecode = "SELECT `rcode` as 'รหัส', finchcode.`ccode`,finrecode.`name` as 'รหัสรายรับทางการเงิน' ,finrecode.`status` as 'สถานะการเปิดใช้งาน',finchcode.`name` as 'รหัสรายได้' FROM  finrecode LEFT JOIN (SELECT * FROM finchcode WHERE `status` = 1) as finchcode ON finrecode.`ccode` = finchcode.`ccode`"
    Dim connect As CONDB = CONDB.NewConnection()
    Property SelectFinrecode_() As String
        Get
            Return SelectFinrecode
        End Get
        Set(value As String)

        End Set
    End Property
    Property RCODE_ As Integer
        Get
            Return RCODE
        End Get
        Set(value As Integer)
            RCODE = value
        End Set
    End Property
    Property CCODE_ As Integer
        Get
            Return CCODE
        End Get
        Set(value As Integer)
            CCODE = value
        End Set
    End Property
    Property NAMER_ As String
        Get
            Return NAMER
        End Get
        Set(value As String)
            NAMER = value
        End Set
    End Property
    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Public Sub insertFinrecodeData()
        If TypeOf NAMER Is String Then
            If connect.GetTable("SELECT `name` FROM finrecode WHERE  `name` = '" & NAMER & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                connect = CONDB.NewConnection()
                connect.BeginTrans()
                Try
                    Dim sql As String
                    sql = "INSERT INTO finrecode"
                    sql += "(`name`,`ccode`,`status`)"
                    sql += "VALUES ("
                    sql += "'" & NAMER & "',"
                    sql += "'" & CCODE & "',"
                    sql += "'" & STATUS & "')"
                    connect.ExecuteNonQuery(sql)
                    connect.CommitTrans()
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    connect.RollbackTrans()
                    MsgBox(ex.ToString)
                Finally
                    connect.Dispose()
                End Try
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
    Public Sub editFinrecodeData()
        If TypeOf NAMER Is String Then
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
                sql = "UPDATE finrecode SET"
                sql += "`name` = '" & NAMER & "',"
                sql += "`ccode` = '" & CCODE & "',"
                sql += "`status` = '" & STATUS & "' "
                sql += "WHERE `rcode` = '" & RCODE & "';"
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub

End Class
